/*
 * @Author: 曹捷
 * @Date: 2020-07-28 14:42:47
 * @LastEditors: 曹捷
 * @LastEditTime: 2020-07-28 14:46:28
 * @Description: 用户是否关注逻辑
 */
export default {
    computed: {
        focusName() {
            return this.dataInfo.isFocus === 1 ? '已关注' : '关注'
        },
        hasSelf() {
            let user = this.$app.getUserInfo()
            return this.dataInfo[this.id] === user.userId
        },
    },
    methods: {
        initFocus() {
            this.$http.getFocusByUserId(this.dataInfo[this.id]).then((res) => {
                this.$set(this.dataInfo, 'isFocus', res)
            })
        },
        focusUser() {
            let param = {
                beFocusedId: this.dataInfo[this.id],
                actionFlag: this.dataInfo.isFocus ? 0 : 1,
            }
            if (this.dataInfo.isFocus === 1) {
                uni.showModal({
                    title: '提示',
                    content: '是否取消关注',
                    success: (res) => {
                        if (res.confirm) {
                            this.$http.focusUser(param).then((res) => {
                                this.$show('取关成功')
                                this.$set(this.dataInfo, 'isFocus', 0)
                            })
                        }
                    },
                })
            } else {
                this.$http.focusUser(param).then((res) => {
                    this.$show('关注成功')
                    this.$set(this.dataInfo, 'isFocus', 1)
                })
            }
        },
    },
}